
// 召唤兽打内丹 {"召唤兽":1,"内丹":19}

// @ts-ignore
export function execute(client_id, message_json) {
    let characters = G.Characters.get_current_login_characters(client_id);
    let pet_index = message_json["召唤兽"] - 1;
    let item_index = message_json["内丹"] - 1;
    let pet_data = characters["召唤兽"][pet_index];
    if (pet_data === undefined) {
        ClientUtils.send_basic_prompt(client_id, "召唤兽不存在");
        return;
    }
    if (pet_data["参战信息"] === 1) {
        ClientUtils.send_basic_prompt(client_id, "请先取消召唤兽的参战状态");
        return;
    }
    let item = characters["道具"][item_index];
    if (!item) {
        ClientUtils.send_basic_prompt(client_id, "#背包内不存在物品");
        return;
    }
    if (item["总类"] !== 203) {
        ClientUtils.send_basic_prompt(client_id, "#请选择召唤兽内丹");
        return;
    }

    if (pet_data["内丹"]["数据"].length === 6) {
        ClientUtils.send_basic_prompt(client_id, "你的召唤兽内丹技能已满，不能继续进行学习。");
        return;
    }
    for (let index = 0; index < pet_data["内丹"]["数据"].length; index++) {
        let element = pet_data["内丹"]["数据"][index];
        if (element["技能"] === item["特效"]) {
            ClientUtils.send_basic_prompt(client_id, "你的召唤兽已经学习了此内丹技能，不能继续进行学习。");
            return;
        }
    }
    pet_data["内丹"]["数据"].push({ "技能": item["特效"], "等级": 1 });
    ClientUtils.send_basic_prompt(client_id, `恭喜, 你的${pet_data["名称"]}学会了#G/${item["特效"]}`);
    G.Characters.remove_item(characters["id"], "道具", item_index, 1);
    //刷新召唤兽列表
    ClientUtils.send_client_message(client_id, 16, characters["召唤兽"]);
    //刷新内丹道具栏
    ClientUtils.send_characters_client_message(characters["id"], 67, { "道具": characters["道具"] });
    //清除已选择内丹内容
    ClientUtils.send_client_message(client_id, 66);
    //通知客户端刷新道具数据
    G.Characters.refrush_item_data(characters["id"], ["道具"]);
}